var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import typescript from '@rollup/plugin-typescript';
import viteCompression from 'vite-plugin-compression';
import path from 'path';
import { readFileSync } from 'fs';
import svgr from 'vite-plugin-svgr';
/**
 *  resolve 路径拼接
 * @param str
 */
var resolve = function (str) {
    return path.resolve(__dirname, str);
};
/**
 * 获取package.json中的version
 */
var packageJson = JSON.parse(readFileSync('./package.json', { encoding: 'utf-8' }));
/**
 * 全局变量
 */
var globals = __assign({}, ((packageJson === null || packageJson === void 0 ? void 0 : packageJson.dependencies) || {}));
// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        react(),
        svgr(),
        typescript({
            target: 'es5',
            rootDir: resolve('packages/'),
            declaration: true,
            declarationDir: resolve('dist'),
            exclude: resolve('node_modules/**'),
            allowSyntheticDefaultImports: true
        }),
        viteCompression({
            verbose: true,
            disable: false,
            threshold: 10240,
            algorithm: 'gzip',
            ext: '.gz'
        })
    ],
    build: {
        cssCodeSplit: true,
        outDir: 'dist',
        lib: {
            // 组件库源码的入口文件
            entry: resolve('packages/index.tsx'),
            // 组件库名称
            name: 'hades-design',
            // 文件名称, 打包结果举例: zoom-design.cjs
            fileName: 'hades-design',
            // 打包格式
            formats: ['es', 'cjs']
        },
        rollupOptions: {
            //排除不相关的依赖
            external: __spreadArray(['react',
                'react-dom',
                'antd',
                'react/jsx-runtime',
                '*.svg'], Object.keys(globals), true)
        }
    }
});
